using UnityEngine;

using SMGCore.EventSys;
using Game.Networking.Events;
using Game.Networking.Client;
using MemoryPack;
using Game.Networking.Utils;

namespace Game.Networking {
	public class S_ForceDisconnectMessageHandler : BaseServerMessageHandler {

		public override ServerPacketID CommandId {
			get {
				return ServerPacketID.ForceDisconnect;
			}
		}

		public override void ProcessMessage(byte[] rawCommand) {
			var command = MemoryPackSerializer.Deserialize<S_ForceDisconnectMessage>(rawCommand);

			Debug.LogFormat("Force disconnected from server. Reason: '{0}'", command.Reason);
			var cc = ClientController.Instance;
			cc.ServerInfo.State = SState.Disconneted;
			EventManager.Fire(new OnForceDisconnectedFromServer { Reason = command.Reason, Message = command.Message });
			NetworkOptions.ClientDisconnectReason = command.Reason;
			NetworkOptions.DisconnectMessage = command.Message;
		}

	}
}
